package numDifferentIntegers;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
    public int numDifferentIntegers(String word) {
        Set<String> set = new HashSet<>();
        int i =0,j = 0,n = word.length();
        while (i<n&&j<n){
            if(!checkFirst(i,word)){
                i++;
            }else if(!checkLast(j,word)){
                j++;
            }else {
                set.add(getNum(word.substring(i,j+1)));
                i++;
                j++;
            }
        }
        return set.size();
    }
    private String getNum(String s) {
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)!='0'){
                return s.substring(i,s.length());
            }
        }
        return "0";
    }
    private boolean checkFirst(int i,String s) {
        if(i == 0) return Character.isDigit(s.charAt(i));
        return Character.isDigit(s.charAt(i))&&!Character.isDigit(s.charAt(i-1));
    }
    private boolean checkLast(int i,String s) {
        if(i == s.length()-1) return Character.isDigit(s.charAt(i));
        return Character.isDigit(s.charAt(i))&&!Character.isDigit(s.charAt(i+1));
    }
}
